Skip to content

Yahoo Weather update, supports forecast for more days#8626

Merged
pvizeli merged 19 commits intohome-assistant:devfrom
fanthos:weatherpanel
Jul 26, 2017
Merged

Yahoo Weather update, supports forecast for more days#8626
pvizeli merged 19 commits intohome-assistant:devfrom
fanthos:weatherpanel

Conversation

@fanthos
Copy link
Copy Markdown
Contributor

@fanthos fanthos commented Jul 24, 2017

Description:

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#3047

Works perfectly with home-assistant/frontend#352 updated weather panel.

Example entry for configuration.yaml (if applicable):

weather:
  - platform: yweather
    name: weather_today

Breaking change
forecast is now every time present and the options was removed.

Checklist:

  • Documentation added/updated in home-assistant.github.io
  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

Tested on my device with hass --debug.

ATTR_FORECAST_TEMP:
self._data.yahoo.Forecast[self._forecast]['high'],
}]
return [{'datetime':v['date'], ATTR_FORECAST_TEMP:int(v['high']), 'templow': int(v['low']),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ':'
line too long (99 > 79 characters)


add_devices([YahooWeatherWeather(yahoo_api, name, forecast)], True)

def _windtostring(degree):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

ATTRIBUTION = "Weather details provided by Yahoo! Inc."

ATTR_FORECAST_DATE = 'datetime'
ATTR_FORECAST_TEMP = 'temperature'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redefinition of unused 'ATTR_FORECAST_TEMP' from line 13

self._data.yahoo.Forecast[self._forecast]['high'],
}]
return [{ATTR_FORECAST_TIME: v['date'], ATTR_FORECAST_TEMP:int(v['high']), ATTR_FORECAST_TEMP_LOW: int(v['low']),
ATTR_FORECAST_CONDITION: CONDITION_CLASSES_LIST[int(v['code'])]}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

ATTR_FORECAST_TEMP:
self._data.yahoo.Forecast[self._forecast]['high'],
}]
return [{ATTR_FORECAST_TIME: v['date'], ATTR_FORECAST_TEMP:int(v['high']), ATTR_FORECAST_TEMP_LOW: int(v['low']),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (121 > 79 characters)

ATTRIBUTION = "Weather details provided by Yahoo! Inc."

CONF_FORECAST = 'forecast'
ATTR_FORECAST_TIME = 'datetime'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redefinition of unused 'ATTR_FORECAST_TIME' from line 13

from homeassistant.components.weather import (
WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST_TEMP)
from homeassistant.const import (TEMP_CELSIUS, CONF_NAME, STATE_UNKNOWN)
WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (90 > 79 characters)

Copy link
Copy Markdown
Member

@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove UI change from this PR

vol.Optional(CONF_FORECAST, default=0):
vol.All(vol.Coerce(int), vol.Range(min=0, max=5)),
vol.Optional(CONF_FORECAST, default=5):
vol.All(vol.Coerce(int), vol.Range(min=0, max=5)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change.

int(self._data.yahoo.Now['code']) in v][0]
except IndexError:
return STATE_UNKNOWN
return CONDITION_CLASSES_LIST[int(self._data.yahoo.Now['code'])]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should catch ValueError and IndexError


for cond, condlst in CONDITION_CLASSES.items():
for condi in condlst:
CONDITION_CLASSES_LIST[condi] = cond
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not allow to use globals. You need do that inside data with a membervariable

Copy link
Copy Markdown
Contributor Author

@fanthos fanthos Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONDITION_CLASSES_LIST should be a const, so I think I forget to move the init code into globle scope.

CONDITION_CLASSES_LIST = [str(x) for x in range(0, 50)]

for cond, condlst in CONDITION_CLASSES.items():
    for condi in condlst:
        CONDITION_CLASSES_LIST[condi] = cond

ATTR_FORECAST_TEMP:
self._data.yahoo.Forecast[self._forecast]['high'],
}]
if self._forecast == None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparison to None should be 'if cond is None:'

fanthos added 3 commits July 24, 2017 21:16
This reverts commit 28b4972.

revert unintentional submodule change
fix typo, add try catch to another int()
@fanthos
Copy link
Copy Markdown
Contributor Author

fanthos commented Jul 24, 2017

@pvizeli
everything should fixed

fabaff
fabaff previously requested changes Jul 25, 2017
def forecast(self):
"""Return the forecast array."""
if not self._forecast:
return []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed...CONF_FORECAST will never be None as it defaults to 5 if not provided.

return self._data.yahoo.Wind['speed']

@property
def wind_bearing(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bearing not speed.

return STATE_UNKNOWN
return CONDITION_CLASSES_LIST[int(self._data.yahoo.Now['code'])]
except (ValueError, IndexError):
return ''
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to return STATE_UNKNOWN instead of an empty string?

@fanthos
Copy link
Copy Markdown
Contributor Author

fanthos commented Jul 25, 2017

Done
@fabaff

Copy link
Copy Markdown

@myusuf3 myusuf3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me now. nice work @fanthos

vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_FORECAST, default=0):
vol.All(vol.Coerce(int), vol.Range(min=0, max=5)),
vol.Optional(CONF_FORECAST, default=5):
Copy link
Copy Markdown
Member

@pvizeli pvizeli Jul 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't make a breaking change. I see no reason to change this now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The forecast in yaml works different from the old one, so I think maybe its better to change forecast to something like forecast_days.

'exceptional': [0, 1, 2, 3, 4, 25, 36],
}

_CONDITION_CLASSES_MAX = 50
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

return [k for k, v in CONDITION_CLASSES.items() if
int(self._data.yahoo.Now['code']) in v][0]
except IndexError:
return hass.data[DATA_CONDITION][int(self._data.yahoo.Now['code'])]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'hass'

_LOGGER.error("Yahoo! only support %d days forecast",
len(yahoo_api.yahoo.Forecast))
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line contains whitespace

@fanthos
Copy link
Copy Markdown
Contributor Author

fanthos commented Jul 26, 2017

Thanks for the push.
When I am trying the Yahoo API on my computer, I received forecast data for 10 days.
https://developer.yahoo.com/weather/

@home-assistant home-assistant deleted a comment from houndci-bot Jul 26, 2017
@home-assistant home-assistant deleted a comment from houndci-bot Jul 26, 2017
@home-assistant home-assistant deleted a comment from houndci-bot Jul 26, 2017
@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Jul 26, 2017

Anyway. We had the data present, so we can show the data to UI :) It cost not more if we don't use it.

@home-assistant home-assistant deleted a comment from houndci-bot Jul 26, 2017
@fanthos
Copy link
Copy Markdown
Contributor Author

fanthos commented Jul 26, 2017

I think some text like weather condiction, and some other common fields should goes to weather platform code.

@pvizeli pvizeli merged commit abcfcdd into home-assistant:dev Jul 26, 2017
@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Jul 26, 2017

👍

@rpitera
Copy link
Copy Markdown

rpitera commented Aug 3, 2017

Since the update, I am seeing some unusually high temperatures in my area.

yweather

All the other data are correct, but I'm pretty sure it's not 185 degrees out, despite feeling like it.

Issue opened: #8758

dethpickle pushed a commit to dethpickle/home-assistant that referenced this pull request Aug 18, 2017
…#8626)

* work on weather panel

* update yahooweather with more forecast details

* Update yweather to allow user input forecast date

* fix for houndci

* fix long line

* fix1

* Revert "work on weather panel"

This reverts commit 28b4972.

revert unintentional submodule change

* fix2

fix typo, add try catch to another int()

* fix pylint

* fix3

* fix4

* Update yweather.py

* Update yweather.py

* Remove global data construct

* Yahoo API support only 5 days forecast

* remove forecast

* fix lint

* fix lint p2

* Update yweather.py
@home-assistant home-assistant locked and limited conversation to collaborators Dec 11, 2017
@fanthos fanthos deleted the weatherpanel branch April 12, 2018 07:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants